package com.jsbs.iam.common.core.utils;

public class PageHelper  {
    private int currPage;
    private int pageSize;
    private int totalPage;
    private int totalRecord;
    private int beginIndex;

    public int getCurrPage() {
        return currPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public int getTotalRecord() {
        return totalRecord;
    }

    public int getBeginIndex() {
        return beginIndex;
    }

    public void init(){
        if (currPage == 0){
            currPage=1;
        }

        if (pageSize == 0){
            pageSize =10;
        }

        beginIndex = (currPage -1) * pageSize;
    }

    public void calculate(int count){
        this.totalRecord = count;
        if (count ==0){
            totalPage =0;
        }
        totalPage = count /pageSize + (count % pageSize ==0 ?0 :1);
    }

    public void setCurrPage(int currPage) {
        this.currPage = currPage;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
    }

    public void setBeginIndex(int beginIndex) {
        this.beginIndex = beginIndex;
    }

    @Override
    public String toString() {
        return "PageHelper{" +
                "currPage=" + currPage +
                ", pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", totalRecord=" + totalRecord +
                ", beginIndex=" + beginIndex +
                '}';
    }
}
